﻿<%@ WebHandler Language="C#" Class="messageFile" %>

using System;
using System.Web;
using CCH.DAO;
using CCH.Entity;
using System.IO;

public class messageFile : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        int file_no = int.Parse(context.Request.QueryString["file_no"]);

        messagefile file = new messagefileDAO().Get_messagefile(file_no);

        if (File.Exists(file.file_path))
        {
            context.Response.Buffer = true;
            context.Response.Clear();
            context.Response.ContentType = "application/download";
            context.Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(file.file_name, System.Text.Encoding.UTF8) + ";");

            //輸出檔案
            context.Response.BinaryWrite(File.ReadAllBytes(file.file_path));
            context.Response.Flush();
            context.Response.End();
        }
        else
        {
            context.Response.Write("查無此檔案!!");
        }


    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}